package com.pmcc.core.entity.security;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.pmcc.core.entity.BaseEntity;
import com.pmcc.core.enums.RoleType;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.List;
import java.util.Set;

/**
 * Created by syk on 17/7/6.
 */
@Getter
@Setter
@Entity
@Table(name = "SYS_ROLE")
public class Role extends BaseEntity {

    @Column(length = 20)
    private String code;// 角色编号

    @Column(length = 100)
    private String name;//角色名称

    @Column(length = 11)
    private String state;//状态

    @Enumerated(EnumType.STRING)
    @Column(length = 20)
    private RoleType type;//角色类型

    @Column(length = 100)
    private String description;//描述

    @JsonIgnore
    @ManyToMany(mappedBy = "roleList", fetch = FetchType.EAGER)
    private List<Employee> employeeList;


    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(
            name = "SYS_ROLE_MENU",
            joinColumns = {@JoinColumn(name = "ROLE_ID", referencedColumnName = "ID")},
            inverseJoinColumns = {@JoinColumn(name = "MENU_ID", referencedColumnName = "ID")})
    @JsonIgnore
    private Set<Menu> menuSet;
}
